package com.ping.study.service.tx;

import com.ping.study.model.dto.tx.MatchListRequest;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.time.format.DateTimeFormatter;

@Service
public class SportsQqService {

    private final WebClient webClient;
    private static final DateTimeFormatter DATE_FORMATTER =
            DateTimeFormatter.ofPattern("yyyy-MM-dd");

    public SportsQqService(WebClient.Builder webClientBuilder) {
        this.webClient = webClientBuilder
                .baseUrl("https://matchweb.sports.qq.com")
                .defaultHeader("User-Agent", "YourApp/1.0")
                .build();
    }

    public Mono<String> getMatchList(MatchListRequest request) {
        request.validate(); // 参数校验

        return webClient.get()
                .uri(uriBuilder -> uriBuilder
                        .path("/matchUnion/list")
                        .queryParam("columnId", request.getColumnId())
                        .queryParam("startTime", request.getStartTime().format(DATE_FORMATTER))
                        .queryParam("endTime", request.getEndTime().format(DATE_FORMATTER))
                        .build())
                .retrieve()
                .bodyToMono(String.class);
    }
}